package org.iteam.xlz.manager.timer;

import java.io.File;
import java.util.List;
import java.util.TimerTask;

import org.iteam.commons.utils.DateUtil;
import org.iteam.xlz.core.entity.images.ImagesDelete;
import org.iteam.xlz.core.service.images.ImagesService;

public class ImagesTimerTask extends TimerTask{

	String path;
	public ImagesTimerTask(String path){
		this.path=path;
	}
	@Override
	public void run() {
		System.out.println("图片删除定时任务开始执行。。。"+DateUtil.currentTime());	
		boolean flag=ImagesService.getInstance().DrupYesterDayTemp();
		if(flag){
			System.out.println("IMAGESTEMP表数据迁移成功...");
			List<ImagesDelete> list= ImagesService.getInstance().getAll();
			
			for(ImagesDelete id:list){
				File file=new File(this.path.replace("/xlz-manager",id.getPath()));
				file.deleteOnExit();
			}
			ImagesService.getInstance().clear();
			System.out.println("删除了"+list.size()+"张图片...");
		}else{
			System.out.println("IMAGESTEMP表数据迁移失败...");	
		}
		System.out.println("定时任务执行完成...");		
	}
}
